//var PauseTime : int = 10;
var EnablePause : boolean = true;
var changeLook: boolean = false;
var degrees : float = 180;
static var rails : SplineController = null;

enum CheckpointState{PlayerHere, PlayerNotHere}

var currentState : CheckpointState = CheckpointState.PlayerNotHere;

var lm : LaunchManager = null;

var ml : MouseLook = null;

function Start(){
  var gameobject = GameObject.Find("Player");
   // (ScriptName is the name of the javascript file)
   ml = gameobject.GetComponentInChildren(MouseLook);
  var other : SplineController;
  rails = gameobject.GetComponent("SplineController");
}

function PauseMotion(){
  Debug.Log("in here");
  if(changeLook){
    //ml.rotateTo(degrees);
    ml.RotateObject(Vector3(0,180,0), 2,2);
    }
  if(EnablePause){
    currentState = CheckpointState.PlayerHere;
    var arr = new Array();
    arr.push("PlayerHere");
    arr.push(this);
    SendMessageUpwards ("setMotionState", arr);
    rails.StopMotion();
    //yield WaitForSeconds (PauseTime);
    //rails.ToggleMotion();
    }
  }

function StartMotion(){
  if(EnablePause){
    currentState = CheckpointState.PlayerNotHere;
    var arr = new Array();
    arr.push("PlayerNotHere");
    arr.push(this);
    SendMessageUpwards ("setMotionState", arr);
    rails.StartMotion();
    //yield WaitForSeconds (PauseTime);
    //rails.ToggleMotion();
    }
  }
  
function getState(){
  return currentState;
} 
 
function OnTriggerEnter (other : Collider) {
    //Debug.Log("hit checkpoint" + this);
    PauseMotion();
}